package com.spring.boot.springBoot.threadPool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * Created by pactera on 2018/1/8.
 */
@Slf4j
@Component
public class MyTask {


    /**
     * Async  开启异步
     * threadPoolExcetor  使用自定的线程池，如果不添加这个bean名称，会使用默认的线程池
     *
     * @param k
     */
    @Async("threadPoolExcetor")
    public void doTask(int k){
        log.info("*****************调用第"+k+"个线程数*************************");
        for(int i = 0;i<10000;i++){
            log.info("*****************调用第"+k+"个线程数*************************");
        }
    }

    /**
     * 带有返回结果的多线程
     * @param k
     * @return
     */

    @Async("threadPoolExcetor")
    public Future<String> asyncFutureResult(int k){

        Future<String> result = new AsyncResult<>("success"+k);
        return result;
    }

}
